package org.example.vertx;

import io.vertx.core.Vertx;

public class VertxTest {
    public static void main(String[] args) {
        VertxTest vertxTest = new VertxTest();
        vertxTest.testBlockingCorrect();
    }

    public void testBlockingCorrect() {
        Vertx vertx = Vertx.vertx();
        vertx.executeBlocking(future -> {
            try {
                Thread.sleep(1000);
//                future.complete("hello world");
                future.complete(true);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, res -> {
            Object result = res.result();
            System.out.println("res type:" + result.getClass().getTypeName());
            System.out.println(result);
        });
    }

    public void testBlockingError() {
        Vertx vertx = Vertx.vertx();
        vertx.executeBlocking(future -> {
            try {
                Thread.sleep(1000);
                future.fail("hello world");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, res -> {
            Object result = res.result();
            System.out.println(result);
        });
    }


}
